﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Text.RegularExpressions;
using System.Configuration;

namespace CECB
{
    /// <summary>
    /// Interaction logic for DashSlideSettings_Window.xaml
    /// </summary>
    public partial class DashSlideSettings_Window : Window
    {
        public DashSlideSettings_Window()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (new Dss.Methods.UserLogin().UserLoginClick(textBox1.Text.Trim(),textBox2.Text.Trim() ))
            {
                MessageBox.Show(" Password Change successfully  ", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
                MessageBox.Show("Enter Valide UserName And Password", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
             
        }

        private void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void textBox5_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            
        }

        private void textBox5_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox5.Clear();
        }

        private void textBox6_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox6.Clear();
        }

        private void SaveEmail_Click(object sender, RoutedEventArgs e)
        {

            if (textBox5.Text.Length != 0 && (!Regex.IsMatch(textBox5.Text, @"^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$")))
            {
                MessageBox.Show("Enter valid Email Address", "Message", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else {
                 
                    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                    config.AppSettings.Settings["Gmail"].Value = textBox5.Text.ToString();
                    config.AppSettings.Settings["GmailPassword"].Value = new Dss.Methods.UserLogin().base64Encode(textBox6.Password.ToString());
                    config.Save(ConfigurationSaveMode.Modified);

                    ConfigurationManager.RefreshSection("appSettings");
                    MessageBox.Show("Account details saved successfully", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            textBox5.Text = "Email Username";
            textBox6.Password = "111111";
        }

        private void textBox3_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox3.Clear();
           // textBox3.c
        }

        private void textBox4_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox4.Clear();
        }

        private void textBox1_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox1.Clear();
        }

        private void textBox2_GotFocus(object sender, RoutedEventArgs e)
        {
            textBox2.Clear();
        }
    }
}
